package com.open.common.utils;

import java.util.Collection;
import java.util.Iterator;
import java.util.Map;

/**
 * @author dashu
 * @date 2025/1/25 15:36
 * @description 提供一组 API 用于快速校验、操作数组或集合对象。
 */
public class CollectionUtils {

    public static boolean isEmpty(Iterable<?> iterable) {
        if (iterable == null) {
            return true;
        }
        if (iterable instanceof Collection<?>) {
            return ((Collection<?>) iterable).isEmpty();
        }
        Iterator<?> iterator = iterable.iterator();
        return !iterator.hasNext();
    }

    public static boolean isEmpty(Collection<?> collection) {
        return collection == null || collection.isEmpty();
    }

    public static boolean isEmpty(Map<?, ?> map) {
        return map == null || map.isEmpty();
    }

    public static <T> boolean isEmpty(T[] array) {
        return array == null || array.length == 0;
    }

    public static boolean isEmpty(long[] array) {
        return array == null || array.length == 0;
    }

    public static boolean isEmpty(int[] array) {
        return array == null || array.length == 0;
    }

    public static boolean isEmpty(short[] array) {
        return array == null || array.length == 0;
    }

    public static boolean isEmpty(char[] array) {
        return array == null || array.length == 0;
    }

    public static boolean isEmpty(byte[] array) {
        return array == null || array.length == 0;
    }

    public static boolean isEmpty(double[] array) {
        return array == null || array.length == 0;
    }

    public static boolean isEmpty(float[] array) {
        return array == null || array.length == 0;
    }

    public static boolean isEmpty(boolean[] array) {
        return array == null || array.length == 0;
    }


    public static boolean isNotEmpty(Iterable<?> iterable) {
        return isEmpty(iterable) == false;
    }

    public static boolean isNotEmpty(Collection<?> collection) {
        return isEmpty(collection) == false;
    }

    public static boolean isNotEmpty(Map<?, ?> map) {
        return isEmpty(map) == false;
    }

    public static <T> boolean isNotEmpty(T[] array) {
        return isEmpty(array) == false;
    }

    public static boolean isNotEmpty(long[] array) {
        return isEmpty(array) == false;
    }

    public static boolean isNotEmpty(int[] array) {
        return isEmpty(array) == false;
    }

    public static boolean isNotEmpty(short[] array) {
        return isEmpty(array) == false;
    }

    public static boolean isNotEmpty(char[] array) {
        return isEmpty(array) == false;
    }

    public static boolean isNotEmpty(byte[] array) {
        return isEmpty(array) == false;
    }

    public static boolean isNotEmpty(double[] array) {
        return isEmpty(array) == false;
    }

    public static boolean isNotEmpty(float[] array) {
        return isEmpty(array) == false;
    }

    public static boolean isNotEmpty(boolean[] array) {
        return isEmpty(array) == false;
    }
}
